package cse474_MultiThreadedHTTPServer.Server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import javax.swing.JOptionPane;
import cse474_MultiThreadedHTTPServer.Logger.LogWindow;
import cse474_MultiThreadedHTTPServer.Logger.ThreadInfo;
import cse474_MultiThreadedHTTPServer.Server.HttpServer;

public class Main {
	static int socketNumber;
	/**
	 * @param args
	 * @throws IOException 
	 */
	
	public static void main(String[] args)  {
		// TODO Auto-generated method stub
		socketNumber = Integer.parseInt(JOptionPane.showInputDialog(null,"Please enter the port number"));
		int threadId = 0;
		ServerSocket socket= null;
		try {
			socket = new ServerSocket(socketNumber);
		} catch (IOException e1) {
			System.err.println("asd0");
		}
		Vector<ThreadInfo> threadInfo = new Vector<ThreadInfo>();
		LogWindow l = new LogWindow(threadInfo);
		l.setVisible(true);
		while(true) {
			Socket newSocket;
			try {
				newSocket = socket.accept();
				new Thread(new HttpServer(newSocket,++threadId,threadInfo)).start();
			} catch (IOException e) {
				System.err.println("asd1");
			}
			
			
		}
		
	}

}
